package com.wiwl.dao.hibernate;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.wiwl.dao.interfaces.IAvisoDAO;
import com.wiwl.domain.Aviso;
import com.wiwl.web.filtro.FiltroAviso;

@Repository
public class AvisoDAO extends GenericHibernateDAO<Aviso> implements IAvisoDAO {

	@Autowired	
	public AvisoDAO(SessionFactory sf) {
		super(sf);
	}
	
	private Criteria parseToCriteria(FiltroAviso filtro){
		Criteria criteria = this.createCriteria();
		
		if(filtro.getEmpresaId()!= null && !filtro.getEmpresaId().equalsIgnoreCase("")){
			criteria.add(Restrictions.eq("empresaId", filtro.getEmpresaId()));
		}
		
		if(filtro.isConPostulantes()){
			criteria.add(Restrictions.eq("", filtro.isConPostulantes()));
		}
		
		return criteria;
	}
	
	
	public List<Aviso> findAviso(FiltroAviso filtro) {
		return findByCriteria(parseToCriteria(filtro));
	}
}
